package com.j.lemon.learn.leecode;

/**
 * @Author lijunjun
 * @Date 2019-11-01 15:49
 * @Description
 */

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public static void main(String[] args) {

//        int a [] = new int[]{9};
//        int b [] = new int[]{1,9,9,9,9,9,9,9,9,9};
//
//        ListNode result = addTwoNumbers(gen(a),gen(b));
        System.out.println(13 / 10);

    }

    public static ListNode gen(int [] arr){
        ListNode l1 = new ListNode(0);
        ListNode l1Temp = null;
        for (int i = 0 ;i<arr.length;i++) {
            if(i==0){
                l1Temp = new ListNode(arr[i]);
                l1.next = l1Temp;
            }else{
                ListNode l = new ListNode(arr[i]);
                l1Temp.next = l;
                l1Temp = l;

            }
        }
        return l1.next;
    }


    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        List<ListNode> list = new ArrayList<>();
        list.add(l1);
        list.add(l2);
        BigInteger result = BigInteger.ZERO;
        for(ListNode node : list){
            ListNode temp = node;
            int num =0 ;
            BigInteger sum = BigInteger.ZERO;
            BigInteger ten = new BigInteger("10");
            sum = sum.add(ten.pow(num).multiply(new BigInteger(String.valueOf(node.val))));
            while(temp.next != null){
                num ++;
                sum =sum.add(ten.pow(num).multiply(new BigInteger(String.valueOf(temp.next.val))));
                temp = temp.next;
            }
            result =result.add(sum);
        }
        ListNode next = new ListNode(0);
        ListNode temp = new ListNode(0);

        String res = result.toString();
        for(int i = res.length()-1;i>=0;i--){

            char c = res.charAt(i);
            String s = String.valueOf(c);
            int in = Integer.parseInt(s);
            if(i == res.length()-1){
                temp = new ListNode(in);
                next.next=temp;
            }else{
                ListNode l = new ListNode(in);
                temp.next = l;
                temp = l;
            }
        }
        return next.next;
    }
}

 class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
